<template>
  <div>
    <van-nav-bar
      :z-index="999"
      :fixed="true"
      left-arrow
      @click-left="onClickLeft"
      :placeholder="true"
      title="修改银行卡"
    ></van-nav-bar>

    <div class="bank-card">
      <div class="ce_basic">
        <p>银行类型</p>
        <select v-model="type" class="ce_type">
          <option
            v-for="(item, index) in bankType"
            :key="index"
            :value="item.dictValue"
            >{{ item.dictLabel }}</option
          >
        </select>
      </div>
      <van-cell-group>
        <van-field v-model="number" type="number" label="银行卡号" />
      </van-cell-group>
      <div @click="affirm" class="btn-binding">确认绑卡</div>
    </div>
  </div>
</template>

<script>
// BankCardVerification
import { BankCard, GreenCard } from "../../../assets/js/api/user";
import { Toast } from "vant";
export default {
  name: "BankCard",
  data() {
    return {
      type: "",
      number: "", // 银行卡号
      bankType: [] // 银行类型
    };
  },

  mounted() {
    BankCard().then(res => {
      this.bankType = res.data;
    });
  },

  methods: {
    // 确认按钮触发的事件
    affirm() {
      // BankCardVerification(this.number).then(res=>{
      //   console.log(res)
      // })
      if (this.type === "") {
        Toast("请选择银行卡类型");
        return;
      }
      if (this.number === "") {
        Toast("银行卡号不能为空");
        return;
      }
      let obj = {
        yhtype: this.type,
        yhk: this.number
      };
      GreenCard(obj).then(res => {
        if (res.code == 0) {
          Toast.success("绑卡成功");
          this.$router.go(-1);
        }
      });
    },

    onClickLeft() {
      this.$router.go(-1);
    }
  },
  created() {
    let dsBridge = require("dsbridge");
    dsBridge.call("goBack", "", function() {
      history.go(-1);
    });
  }
};
</script>

<style></style>
